import Vue from 'vue'


export default {

    category: Blockly.Categories.bepart ,
    
    color: [
        Blockly.Colours.operators.primary,
        Blockly.Colours.operators.secondary,
        Blockly.Colours.operators.tertiary
    ] ,

    previousStatement: true ,
    nextStatement: true ,

    init() {
        this.appendDummyInput()
            .appendField("显示消息")
            .appendField(new Blockly.FieldDropdown(() => {
                return [
                    ['通知' , 'info'] ,
                    ['成功' , 'success'] ,
                    ['错误' , 'error'] ,
                    ['警告' , 'warning'] ,
                    ['等待' , 'loading'] ,
                ]
            }), 'type')
        this.appendValueInput("what")
    } ,

    // run (args: any, util: any, runtime: any) {
    //     if(args.what!=null && args.what!=undefined) {
    //         Vue.prototype.$Message[args.type]({
    //             content: args.what.toString()
    //         })
    //     }
    // } ,

    coder: {
        JavaScript(block: any, coder: any) {
            let type = block.getFieldValue('type')
            let content = coder.valueToCode(block, "what", coder.ORDER_ASSIGNMENT) || '""'
            return `${coder.indentString()}telnet.send(0,6,\`EmitMessage("${type}", ${content})\`)\n`
        }
    }
}